#!/bin/bash

ECHO="echo -e"

function log() {
    $ECHO "$*"
}

dirs=$*

CUR=`pwd`

function do_itoy_file() {
    filefullname="$CUR/$1"
    name_no_suffix=${filefullname%.*}
    filename=${name_no_suffix##*/}

    ## fetch positioin
    tmp_name_prefix=${1%.*}
    tmp_name_remove_last=${1%/*}
    if [ "$JKTR" == "yes" ]; then
        saveposition=$CUR/travers/$tmp_name_remove_last
        jkitoy -f $filefullname -n $filename -s $saveposition -revert
    else
        saveposition=$CUR/jkity/$tmp_name_remove_last
        jkitoy -f $filefullname -n $filename -s $saveposition
    fi
}

function do_one_time() {
    dir=$1
    for file in $dir/*; do
        if [ -d $file ]; then
            do_one_time $file
        fi
        if [ -f $file ]; then
            log "do with file $CUR/$file"
            do_itoy_file "$file"
        fi
    done
}

for dir in $dirs; do
    do_one_time $dir
done

